#include <iostream>
#include <unistd.h>
#include <cstdint>
#include <string>

#include "Reactor.hpp"
#include "Connection.hpp"
#include "Listener.hpp"
#include "HanderConnection.hpp"
#include "PakageParse.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: [./server port]" << std::endl;
        return 1;
    }
    uint16_t port = std::stoi(argv[1]);

    handerConnection hr(pakageParse::parse);
    listener l(port, hr);
    reactor react;
    react.addConnection(l.getFd(),
                        EPOLLIN | EPOLLET,
                        std::bind(&listener::accepter, &l, std::placeholders::_1),
                        nullptr,
                        nullptr);

    react.dispatcher();
    return 0;
}